/** * 头部菜单 */
<template class="menu-flex">
  <el-menu
    class="el-menu-demo"
    mode="horizontal"
    background-color="#fff"
    text-color="#000"
    active-text-color="#000"
  >
    <div class="menu-flex">
      <el-button class="buttonimg">
        <img
          class="showimg"
          :src="collapsed ? imgsq : imgshow"
          @click="toggle(collapsed)"
        />
      </el-button>
      <!-- <el-submenu index="2" class="submenu">
      <template slot="title">
        超级管理员
        <img src="../icon标/个人.png" class="manager"/>
      </template>

      <el-menu-item index="2-1">设置</el-menu-item>
      <el-menu-item @click="content()" index="2-2">个人中心</el-menu-item>
      <el-menu-item @click="exit()" index="2-3">退出</el-menu-item>
    </el-submenu> -->
      <el-dropdown style="padding:11px 0;">
        <div class="img">
          <span class="el-dropdown-link">
            {{ username }}
          </span>
          <div>
            <img src="../icon标/个人.png" class="manager" />
          </div>
          <div>
            <i class="el-icon-arrow-down el-icon--right"></i>
          </div>
        </div>
        <el-dropdown-menu
          slot="dropdown"
          style="min-width:145px;margin-top:-1px;text-align:center;height:120px;"
        >
          <el-dropdown-item
            @click.native="personalcenter()"
            style="display:flex;justify-content:center;align-items:center;height:40px;"
          >
            <!-- <router-link to="/PersonalCenter">个人中心</router-link> -->
            <img src="../icon标/个人中心 (2).png" />
            <p style="margin-left:8px;">个人中心</p>
          </el-dropdown-item>
<!--          <el-dropdown-item-->
<!--            @click.native="usermanage()"-->
<!--            style="display:flex;justify-content:center;align-items:center;height:40px;"-->
<!--          >-->
<!--            <img src="../icon标/用户管理 (1).png" />-->
<!--            <p style="margin-left:8px;">用户管理</p>-->
<!--          </el-dropdown-item>-->

          <el-dropdown-item
            @click.native="exit()"
            style="display:flex;justify-content:center;align-items:center;height:40px;"
          >
            <img src="../icon标/退出.png" />
            <p style="margin-left:8px;">退出登录</p>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </el-menu>
</template>
<script>
import { loginout } from "../api/userMG";
export default {
  name: "navcon",
  data() {
    return {
      collapsed: true,
      imgshow: require("../icon标/显示导航.png"),
      imgsq: require("../icon标/隐藏导航.png"),
      user: {},
      username: " "
    };
  },
  // 创建完毕状态(里面是操作)
  created() {
    this.user = JSON.parse(localStorage.getItem("userdata"));
    this.selectUserIdentity();
  },
  methods: {
    // 退出登录
    exit() {
      this.$confirm("退出登录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          setTimeout(() => {
            this.$cookies.remove("token");
            this.$store.commit("logout", "false");
            this.$router.push({ path: "/login" });
            this.$message({
              type: "success",
              message: "已退出登录!"
            });
          }, 1000);
          // loginout()
          //   .then(res => {
          //     if (res.success) {
          //       //如果请求成功就让他2秒跳转路由
          //       setTimeout(() => {
          //         this.$store.commit('logout', 'false')
          //         this.$router.push({ path: '/login' })
          //         this.$message({
          //           type: 'success',
          //           message: '已退出登录!'
          //         })
          //       }, 1000)
          //     } else {
          //       this.$message.error(res.msg)
          //       this.logining = false
          //       return false
          //     }
          //   })
          //   .catch(err => {
          //     // 获取图形验证码
          //     this.getcode()
          //     this.logining = false
          //     this.$message.error('退出失败，请稍后再试！')
          //   })
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 切换显示
    toggle(showtype) {
      this.collapsed = !showtype;
      this.$root.Bus.$emit("toggle", this.collapsed);
    },
    personalcenter() {
      this.$router.push("/PersonalCenter");
    },
    async selectUserIdentity() {
      const { data: res } = await this.$axios.get("getInfo");
      this.username = res.data.username;
      const { data: res1 } = await this.$axios.get("getUserIdentity");
      console.log(res1);
      console.log("xxxxx");
    },
    usermanage(){
      this.$router.push("/userManaged");
    }
  }
};
</script>
<style scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
}
.submenu {
  float: right;
}

.buttonimg {
  height: 60px;
  /* background-color: #000; */
  background: transparent;
  border: none;
}
.showimg {
  width: 24px;
  height: 18px;
  position: absolute;
  top: 17px;
  left: 17px;
}
.showimg:active {
  border: none;
}
.manager {
  margin-left: 10px;
}
.el-dropdown-link {
  cursor: pointer;
}
.el-icon-arrow-down {
  font-size: 12px;
}
/* .el-dropdown-menu {
    width: 100px;
    padding: 10px 20px;
} */
.menu-flex {
  display: flex;
  justify-content: space-between;
  margin-right: 35px;
  outline: none;
}
span,
img {
  display: block;
}
.img {
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
</style>
